#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

const char * path = "fifo"; // 读
int main()
{
    if(access(path, F_OK) < 0)
    {
        mkfifo(path, 0666);
    }
    int fd = open(path, O_RDONLY);
    char buffer[1024] = {};
    while(1)
    {
        int n = read(fd, buffer, sizeof(buffer) - 1);
        if(n > 0)
        {
            buffer[n] = 0;
            printf("%s\n",buffer);
        }
        else if(n == 0)
        {
            printf("写进程退出\n");
            break;
        }
        else
        {
            perror("read");
            break;
        }
    }
    return 0;
}